//
//  HMToolBarView.swift
//  WeiBo
//
//  Created by Feng on 2017/6/8.
//  Copyright © 2017年 feng. All rights reserved.
//

import UIKit

class HMToolBarView: UIView {

    var statusCellViewModel: HMStatusCellViewModel?
    {
        didSet {
            
            guard let model = statusCellViewModel else {
                return
            }
            
            //评论按钮文字
            retweetButton.setTitle(model.repostsCount, for: .normal)
            //评论按钮文字
            commentButton.setTitle(model.commentsCount, for: .normal)
            //评论按钮文字
            unlikeButton.setTitle(model.attitudesCount, for: .normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
     
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: --创建控件
    //转发
    let retweetButton = UIButton(title: "评论", titleColor: UIColor.darkGray, fontSize: 14, image: UIImage(named:"timeline_icon_retweet")!, backgroundImage: UIImage(named:"timeline_card_bottom_background")!)
    //评论
    let commentButton = UIButton(title: "转发", titleColor: UIColor.darkGray, fontSize: 14, image: UIImage(named:"timeline_icon_comment")!, backgroundImage: UIImage(named:"timeline_card_bottom_background")!)
    //赞
    let unlikeButton = UIButton(title: "赞", titleColor: UIColor.darkGray, fontSize: 14, image: UIImage(named:"timeline_icon_unlike")!, backgroundImage: UIImage(named:"timeline_card_bottom_background")!)
    
//    //第一条线
//    let firstLineView: UIImageView = HMToolBarView.createLineView()
//    let secondLineView: UIImageView = HMToolBarView.createLineView()
//    //第二条线
//    let secondLineView: UIImageView = createLineView()
    
    //MARK: --添加控件及设置约束
    func setupUI()
    {
        //第一条线
        let firstLineView = createLineView()
        //第二条线
        let secondLineView = createLineView()
        
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(unlikeButton)
        addSubview(firstLineView)
        addSubview(secondLineView)
        
        retweetButton.snp.makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton.snp.trailing)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp.makeConstraints { (make) in
            make.top.trailing.bottom.equalTo(self)
            make.leading.equalTo(commentButton.snp.trailing)
        }
        
        firstLineView.snp.makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp.trailing)
            make.centerY.equalTo(self)
        }
        
        secondLineView.snp.makeConstraints { (make) in
            make.centerX.equalTo(commentButton.snp.trailing)
            make.centerY.equalTo(self)
        }
    }
    
    func createLineView() -> UIImageView
    {
        let lineView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        return lineView
    }
}

